package leetcode5;

import java.util.ArrayList;
import java.util.List;

/*
* 238. 除自身以外数组的乘积*/
public class test14 {
    public int[] productExceptSelf(int[] nums) {
        int[] res = new int[nums.length];
        int[] L = new int[nums.length];
        int[] R = new int[nums.length];
        L[0] = 1;
        R[nums.length - 1] = 1;
        for(int i = 0;i < nums.length - 1;i++){
            L[i + 1] = L[i] * nums[i];
        }
        for(int i = nums.length - 1;i > 0;i--){
            R[i - 1] = R[i] * nums[i];
        }
        for(int i = 0 ;i < nums.length;i++){
            res[i] = L[i] * R[i];
        }
        return res;
    }
}
